package com.accenture.fd.controller;

import java.io.InputStream;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.accenture.fd.entity.AuthorityEntity;
import com.accenture.fd.entity.ClassListEntity;
import com.accenture.fd.entity.DesignEntity;
import com.accenture.fd.entity.ItemControlEntity;
import com.accenture.fd.entity.LogicalDataItemEntity;
import com.accenture.fd.entity.LogicalDataItemModel;
import com.accenture.fd.entity.ScreenItemDescripitonModel;
import com.accenture.fd.entity.ScreenItemDescriptionEntity;
import com.accenture.fd.entity.UploadFileForClassListDto;
import com.accenture.fd.entity.UploadFileForClassListEntity;
import com.accenture.fd.entity.UploadFileForProcessListEntity;
import com.accenture.fd.entity.User;
import com.accenture.fd.service.ImportExcelToDBService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import freemarker.template.utility.StringUtil;

@CrossOrigin
@RestController
public class ImportExcelToDBController {

	@Autowired
	private ImportExcelToDBService service;
	
	@Autowired
    private Environment env;

	/*
	 * request: http://localhost:8080/saveExcelData1
	 * testData: [ { "userid": "zhangwei1", "username": "张威1" },
	 *             { "userid": "zhangwei2", "username": "张威2" } ]
	 */
	@PostMapping(value = "/saveExcelData1")
	public void saveExcelData1(@RequestBody String jsonArray) {

		List<User> userList = new ArrayList<>();
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			userList = objectMapper.readValue(jsonArray, new TypeReference<List<User>>() {
			});
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}

		userList.forEach(t -> System.out.println(t.getUserid() + "----" + t.getUsername()));

		service.saveUserAll(userList);
	}

	/*
	 * request: http://localhost:8080/saveExcelData2
	 * testData: [ { "userid": "zhangwei3", "username": "张威3" },
	 *             { "userid": "zhangwei4", "username": "张威4" } ]
	 */
	@PostMapping(value = "/saveExcelData2")
	public void saveExcelData2(@RequestBody List<User> userList) {

		userList.forEach(t -> System.out.println(t.getUserid() + "----" + t.getUsername()));

		service.saveUserAll(userList);
	}

	@PostMapping(value = "/saveExcelDataToDB")
	public void saveExcelDataToDB(@RequestBody String tableData) {

		//画面項目記述書
		List<ScreenItemDescripitonModel> screenItemDescripitonModelList = new ArrayList<>();
		ObjectMapper objectMapper = new ObjectMapper();
		try {
			screenItemDescripitonModelList = objectMapper.readValue(tableData, new TypeReference<List<ScreenItemDescripitonModel>>() {
			});
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		//画面項目記述書テーブルエンティティにセットする
		List<ScreenItemDescriptionEntity> screenItemDescriptionEntityList = this.setScreenItemDescriptionEntity(screenItemDescripitonModelList);
		//設計書情報一覧テーブルエンティティにセットする
		List<DesignEntity> designEntityList = this.setDesignEntity(screenItemDescripitonModelList);

		//画面項目記述書テーブルに挿入する
		this.service.saveScreenItemDescription(screenItemDescriptionEntityList);
		//設計書情報一覧テーブルに挿入する
		this.service.saveDesign(designEntityList);

	}
	
	@PostMapping(value = "/saveExcelDataToDB1")
	public void saveExcelDataToDB1(@RequestParam("file") MultipartFile file) throws Exception {

		// ファイル
		InputStream inputStream = file.getInputStream();
		
		// Excel　work　作成
		Workbook work = this.getWorkbook(inputStream, file.getOriginalFilename());
		if (null == work) {
			throw new Exception("Excel　work　がありません。");
		}
		
		// 
		this.setScreenItemDescriptionByExcel(work, file.getOriginalFilename());
		// 権限テーブルエンティティにセットする
		this.setAuthorityByExcel(work);
		// 
		this.setItemControlByExcel(work);
		work.close();
		inputStream.close();
	}


	/** 
	 * ScreenItemDescriptionテーブルエンティティにセットする
	 * @param work
	 * @throws Exception
	 */
	private void setScreenItemDescriptionByExcel(Workbook work, String fileName) throws Exception {
		
		// sheet番号
		int sheetNo = Integer.parseInt(env.getProperty("authority.sheetNo"));
		// screen Idの行番号
		int pageIdRowNo = Integer.parseInt(env.getProperty("authority.pageIdRowNo"));
		// screen Idの列番号
		int pageIdCellNo = Integer.parseInt(env.getProperty("authority.pageIdCellNo"));
		// itemの開始行番号
		int itemStartRowNo = Integer.parseInt(env.getProperty("authority.itemStartRowNo"));
		// itemの列番号
		int itemStartCellNo = Integer.parseInt(env.getProperty("authority.itemStartCellNo"));
		
		// sheet設定
		Sheet sheet = work.getSheetAt(sheetNo);
		// screenId設定
		String screenId = sheet.getRow(pageIdRowNo).getCell(pageIdCellNo).toString();
		
		List<ScreenItemDescriptionEntity> entityList = new ArrayList<ScreenItemDescriptionEntity>();
		ScreenItemDescriptionEntity entity = null;
		String screenItemPhysicsName = "";
		HashMap<String, String> physicsDicMap = service.getAllDateList();
		for (int j = itemStartRowNo; j < sheet.getLastRowNum(); j++) {
			Row row = sheet.getRow(j);
			
			//TODO "6"
			entity = new ScreenItemDescriptionEntity();
			entity.setDesignTypeId("画面項目記述書");
			entity.setScreenId(screenId);
			entity.setSection(Integer.parseInt(new java.text.DecimalFormat("0").format(row.getCell(itemStartCellNo).getNumericCellValue())));
			entity.setLevelCd(String.valueOf(Integer.parseInt(new java.text.DecimalFormat("0").format(row.getCell(itemStartCellNo + 1).getNumericCellValue()))));
			entity.setScreenItemName(row.getCell(itemStartCellNo + 3) == null ? "" : row.getCell(itemStartCellNo + 3).toString());
			// Cm00004
			screenItemPhysicsName = row.getCell(itemStartCellNo + 4) == null ? "" : this.getItemPhysicsName(row.getCell(itemStartCellNo + 4).toString(), physicsDicMap);
			entity.setScreenItemPhysicsName(screenItemPhysicsName);
			entity.setIoCd(row.getCell(itemStartCellNo + 5) == null ? "" : row.getCell(itemStartCellNo + 5).toString());
			entity.setTypeCd(row.getCell(itemStartCellNo + 6) == null ? "" : row.getCell(itemStartCellNo + 6).toString());
			entity.setAttributeCd(row.getCell(itemStartCellNo + 7) == null ? "" : row.getCell(itemStartCellNo + 7).toString());
			entity.setTabCd(row.getCell(itemStartCellNo + 8) == null ? "" : row.getCell(itemStartCellNo + 8).toString());
			entity.setRequired(row.getCell(itemStartCellNo + 9) == null ? "" : row.getCell(itemStartCellNo + 9).toString());
			entity.setRangeWide(row.getCell(itemStartCellNo + 11) == null ? "" : row.getCell(itemStartCellNo + 11).toString());
			entity.setRangeSmall(row.getCell(itemStartCellNo + 10) == null ? "" : row.getCell(itemStartCellNo + 10).toString());
			entity.setDigitBranch(row.getCell(itemStartCellNo + 12) == null ? "" : row.getCell(itemStartCellNo + 12).toString());
			entity.setNumberBar(row.getCell(itemStartCellNo + 13) == null ? "" : row.getCell(itemStartCellNo + 13).toString());
			entity.setDisplayFormatCd(row.getCell(itemStartCellNo + 16) == null ? "" : row.getCell(itemStartCellNo + 16).toString());
			entity.setControlCondition(row.getCell(itemStartCellNo + 17) == null ? "" : row.getCell(itemStartCellNo + 17).toString());
			entity.setDataItem(row.getCell(itemStartCellNo + 18) == null ? "" : row.getCell(itemStartCellNo + 18).toString());
			entity.setStatusCd("状態CD");//TODO 状態CD
			entity.setProcessingId(row.getCell(itemStartCellNo + 19) == null ? "" : row.getCell(itemStartCellNo + 19).toString());
			entity.setLoginDate(LocalDate.now());
			entity.setLoginBy("登録者");
			entity.setUpdateDate(LocalDate.now());
			entity.setUpdatedBy("更新者");
			entity.setEffectiveFlag("Y");
			entity.setVersionNumber("0123456789");

			entityList.add(entity);
		}
		
		//画面項目記述書テーブルに挿入する
		this.service.saveScreenItemDescription(entityList);
		
		//設計書情報一覧テーブルエンティティにセットする
		List<DesignEntity> designEntityList = new ArrayList<>();

		DesignEntity designEntity = new DesignEntity();
		//設計書種類ID
		designEntity.setDesignTypeId("画面項目記述書");
		//画面ID
		designEntity.setScreenId(screenId);
		//画面名
		designEntity.setScreenName(sheet.getRow(pageIdRowNo).getCell(pageIdCellNo + 3).toString());
		//TODO 設計書名
		designEntity.setDesignName(fileName);
		//TODO 状態CD
		designEntity.setCheckStatus("状態CD");
		//登録日
		designEntity.setLoginDate(LocalDate.now());
		//登録者
		designEntity.setLoginBy("登録者");
		//更新日
		designEntity.setUpdateDate(LocalDate.now());
		//更新者
		designEntity.setUpdatedBy("更新者");
		//有効フラグ
		designEntity.setEffectiveFlag("Y");
		designEntity.setVersionNumber("9876543210");

		designEntityList.add(designEntity);
		//設計書情報一覧テーブルに挿入する
		this.service.saveDesign(designEntityList);
	}

	/** 
	 * 制御テーブルエンティティにセットする
	 * @param work
	 * @throws Exception
	 */
	private void setItemControlByExcel(Workbook work) throws Exception {
		
		// sheet番号
		int sheetNo = Integer.parseInt(env.getProperty("authority.sheetNo"));
		// screen Idの行番号
		int pageIdRowNo = Integer.parseInt(env.getProperty("authority.pageIdRowNo"));
		// screen Idの列番号
		int pageIdCellNo = Integer.parseInt(env.getProperty("authority.pageIdCellNo"));
		// ItemControl の開始列番号
		int itemControlCellStartNo = Integer.parseInt(env.getProperty("itemControl.itemControlCellStartNo"));
		// ItemControl の終了列番号
		int itemControlCellEndNo = Integer.parseInt(env.getProperty("itemControl.itemControlCellEndNo"));
		// ItemControlLevel1の行番号
		int itemControlLevel1RowNo = Integer.parseInt(env.getProperty("itemControl.itemControlLevel1RowNo"));
		// ItemControlLevel2の行番号
		int itemControlLevel2RowNo = Integer.parseInt(env.getProperty("itemControl.itemControlLevel2RowNo"));
		// itemControlNmの行番号
		int itemControlNmRowNo = Integer.parseInt(env.getProperty("itemControl.itemControlNmRowNo"));
		// itemの開始行番号
		int itemStartRowNo = Integer.parseInt(env.getProperty("authority.itemStartRowNo"));
		// itemの列番号
		int itemStartCellNo = Integer.parseInt(env.getProperty("authority.itemStartCellNo"));
		
		// sheet設定
		Sheet sheet = work.getSheetAt(sheetNo);
		// screenId設定
		String screenId = sheet.getRow(pageIdRowNo).getCell(pageIdCellNo).toString();

		// ItemControlLevel1,ItemControlLevel2,ItemControlNmMap
		Map<Integer, String> itemControlMap = new HashMap<>();
		Integer itemControlLevel1Common = 0;
		for (int i = itemControlCellStartNo; i < itemControlCellEndNo; i++) {
			Integer itemControlLevel1 = Integer.parseInt(new java.text.DecimalFormat("0").format(sheet.getRow(itemControlLevel1RowNo).getCell(i).getNumericCellValue()));
			if (itemControlLevel1 == 0) {
				itemControlLevel1 = itemControlLevel1Common;
			} else {
				itemControlLevel1Common = itemControlLevel1;
			}
//			itemControlLevel1 == 0 ? itemControlLevel1 = itemControlLevel1Common : itemControlLevel1Common = itemControlLevel1;
			Integer itemControlLevel2 = Integer.parseInt(new java.text.DecimalFormat("0").format(sheet.getRow(itemControlLevel2RowNo).getCell(i).getNumericCellValue()));
			String itemControlNm = sheet.getRow(itemControlNmRowNo).getCell(i).toString().replaceAll("\n", "");
			itemControlMap.put(i, itemControlLevel1.toString().concat(":").concat(itemControlLevel2.toString()).concat(":").concat(itemControlNm));
		}
		
		// 権限リスト
		List<ItemControlEntity> entityList = new ArrayList<>();
		ItemControlEntity entity = null;
		for (int j = itemStartRowNo; j < sheet.getLastRowNum(); j++) {
			Row row = sheet.getRow(j);
			
			for (Integer key : itemControlMap.keySet()) {
				entity = new ItemControlEntity();
				// designTypeId(PK1-char-10)
				entity.setDesignTypeId("画面項目記述書");
				// ScreenId(PK2-char-10)
				entity.setScreenId(screenId);
				// section(PK3-bigint)
				String section = String.valueOf(Integer.parseInt(new java.text.DecimalFormat("0").format(row.getCell(itemStartCellNo).getNumericCellValue())));
				entity.setSection(section);
				// controlLevel1
				entity.setControlLevel1(itemControlMap.get(key).split(":")[0]);
				// controlLevel2
				entity.setControlLevel2(itemControlMap.get(key).split(":")[1]);
				// ControlSection
				entity.setControlSection(itemControlMap.get(key).split(":")[2]);
				// Control
				entity.setControl(row.getCell(key).toString());
				entityList.add(entity);
			}
		}
		
		List<String> screenIdList = this.service.selectItemControlByScreenId(screenId);
		if (screenIdList.size() > 0) {
			this.service.delItemControlByScreenId(screenId);
		}
		// Controlテーブルに挿入する
		this.service.saveControl(entityList);
	}

	
	/** 
	 * 権限テーブルエンティティにセットする
	 * @param work
	 * @throws Exception
	 */
	private void setAuthorityByExcel(Workbook work) throws Exception {
		
		// シート番号
		int sheetNo = Integer.parseInt(env.getProperty("authority.sheetNo"));
		// 画面Idの行番号
		int pageIdRowNo = Integer.parseInt(env.getProperty("authority.pageIdRowNo"));
		// 画面Idの列番号
		int pageIdCellNo = Integer.parseInt(env.getProperty("authority.pageIdCellNo"));
		// 権限の開始列番号
		int authorityCellStartNo = Integer.parseInt(env.getProperty("authority.authorityCellStartNo"));
		// 権限の終了列番号
		int authorityCellEndNo = Integer.parseInt(env.getProperty("authority.authorityCellEndNo"));
		// 権限Idの行番号
		int authorityIdRowNo = Integer.parseInt(env.getProperty("authority.authorityIdRowNo"));
		// 権限名の行番号
		int authorityNmRowNo = Integer.parseInt(env.getProperty("authority.authorityNmRowNo"));
		// 項目の開始行番号
		int itemStartRowNo = Integer.parseInt(env.getProperty("authority.itemStartRowNo"));
		// 項目Idの列番号
		int itemStartCellNo = Integer.parseInt(env.getProperty("authority.itemStartCellNo"));
		
		// シート設定
		Sheet sheet = work.getSheetAt(sheetNo);
		// 画面ID設定
		String screenId = sheet.getRow(pageIdRowNo).getCell(pageIdCellNo).toString();

		// 権限ID,権限名Map
		Map<Integer, String> authorityMap = new HashMap<>();
		for (int i = authorityCellStartNo; i < authorityCellEndNo; i++) {
			String authorityId = sheet.getRow(authorityIdRowNo).getCell(i).toString();
			String authorityNm = sheet.getRow(authorityNmRowNo).getCell(i).toString().replaceAll("\n", "");
			authorityMap.put(i, authorityId.concat(":").concat(authorityNm));
		}
		
		// 権限リスト
		List<AuthorityEntity> entityList = new ArrayList<>();
		for (int j = itemStartRowNo; j < sheet.getLastRowNum(); j++) {
			Row row = sheet.getRow(j);
			
			for (Integer key : authorityMap.keySet()) {
				AuthorityEntity entity = new AuthorityEntity();
				// 画面ID
				entity.setScreenId(screenId);
				// 項目ID
				String section = String.valueOf(Integer.parseInt(new java.text.DecimalFormat("0").format(row.getCell(itemStartCellNo).getNumericCellValue())));
				entity.setSection(section);
				// 権限ID
				entity.setAuthorityId(authorityMap.get(key).split(":")[0]);
				// 権限名
				entity.setAuthorityNm(authorityMap.get(key).split(":")[1]);
				// 権限値
				entity.setAuthorityValue(row.getCell(key).toString());
				entityList.add(entity);
			}
		}
		
		List<String> screenIdList = this.service.selAuthority(screenId);
		if (screenIdList.size() > 0) {
			this.service.delAuthority(screenId);
		}
		// 権限テーブルに挿入する
		this.service.saveAuthority(entityList);
	}

	/**
	 * 項目物理名の取得
	 * @param itemName 項目日本語名
	 * @param physicsDicMap　単語辞書
	 * @return　項目物理名
	 */
	private String getItemPhysicsName(String itemName, HashMap<String, String>physicsDicMap) {
		
		if (StringUtils.isEmpty(itemName)) {
			return "";
		}
		
		StringBuilder returnVal = new StringBuilder();

		int lengthTotal = itemName.length();
		int lengthCurrentStart = 0;
		int lengthCurrentEnd = lengthTotal;
		String itemNameCurrent = "";
		do {

			itemNameCurrent = itemName.substring(lengthCurrentStart, lengthCurrentEnd);

			if (StringUtils.isEmpty(physicsDicMap.get(itemNameCurrent))) {
				lengthCurrentEnd--;
			} else {
				returnVal.append(physicsDicMap.get(itemNameCurrent));
				lengthCurrentStart += (lengthCurrentEnd - lengthCurrentStart);
				lengthCurrentEnd = lengthTotal;
			}

		} while (lengthCurrentStart != lengthCurrentEnd);

		return returnVal.toString();
	}
	
	/**
	 * ファイル型チェック
	 * @param inStr
	 * @param fileName
	 * @return
	 * @throws Exception
	 */
	private Workbook getWorkbook(InputStream inStr, String fileName) throws Exception {
		Workbook workbook = null;
		String fileType = fileName.substring(fileName.lastIndexOf("."));
		if (".xls".equals(fileType)) {
			workbook = new HSSFWorkbook(inStr);
		} else if (".xlsx".equals(fileType)) {
			workbook = new XSSFWorkbook(inStr);
		} else {
			throw new Exception("excelファイルをインポートしてください。");
		}
		return workbook;
	}

	@PostMapping(value = "/saveExcelDataToDBForClassList")
	public void saveExcelDataToDBForClassList(@RequestBody List<ClassListEntity> list) {

		//TB00014テーブルに挿入する
		this.service.saveScreenClassListDescription(list.subList(2, list.size()));
	}

	@PostMapping(value = "/saveExcelDataToDBForProcessList")
	public void saveExcelDataToDBForProcessList(@RequestBody List<UploadFileForProcessListEntity> list) {
		//TB00013テーブルに挿入する
		this.service.saveScreenPrcessList(list.subList(2, list.size()));
	}

	//論理データ項目一覧
	@PostMapping(value = "/saveExcelToDbForLgcDtaItem")
	public void saveExcelToDbForLgcDtaItem(@RequestBody List<LogicalDataItemModel> modelList) {

		//CM00001テーブルエンティティにセットする
		List<LogicalDataItemEntity> logicalDataItemEntityList = this.setLogicalDataItemEntity(modelList);
		//CM00001テーブルに挿入する
		this.service.saveLogicalDataItem(logicalDataItemEntityList);

	}

	//TODO "2"
	private List<LogicalDataItemEntity> setLogicalDataItemEntity(List<LogicalDataItemModel> modelList){
		List<LogicalDataItemEntity> entityList = new ArrayList<>();
		for(LogicalDataItemModel model : modelList.subList(2, modelList.size())) {
			LogicalDataItemEntity entity = new LogicalDataItemEntity();
			entity.setConsecutive_no(Integer.parseInt(model.getConsecutive_no()));
			entity.setEntity_physical_name(model.getEntity_physical_name());
			entity.setEntity_logical_name(model.getEntity_logical_name());
			entity.setData_item_name(model.getData_item_name());
			entity.setColumn_cd(model.getColumn_cd());
			entity.setPk(model.getPk());
			entity.setFy(model.getFy());
			entity.setRelated_entity_name(model.getRelated_entity_name());
			entity.setData_type_cd(model.getData_type_cd());
			entity.setSize(Integer.parseInt(model.getSize()));
			entity.setExplanation_items(model.getExplanation_items());
			entity.setLogin_date(LocalDate.now());
			entity.setLogin_by("登録者");
			entity.setUpdate_date(LocalDate.now());
			entity.setUpdate_by("更新者");
			entity.setEffective_flag("Y");

			entityList.add(entity);
		}
		return entityList;
	}

	private List<UploadFileForClassListEntity> setClassListEntity(List<UploadFileForClassListDto> list){
		List<UploadFileForClassListEntity> entityList = new ArrayList<>();
		for(UploadFileForClassListDto dto : list){
			UploadFileForClassListEntity entity = new UploadFileForClassListEntity();
			entity.setClass_pakage(dto.getClass_pakage());
			entity.setClass_comment(dto.getClass_comment());
			entity.setClass_id(dto.getClass_id());
			entity.setClass_type("DTO".equals(dto.getClass_type())?"1":"2");
			entity.setCreate_status("");
			entity.setProcessing_id(dto.getClass_processing_id());
			entity.setResponsibility(dto.getClass_responsibility());
			entity.setScreen_id(dto.getScreen_id());
			entityList.add(entity);
		}
		return entityList;
	}

	//設計書情報一覧テーブルエンティティにセットする
	private List<DesignEntity> setDesignEntity(List<ScreenItemDescripitonModel> modelList){
		List<DesignEntity> entityList = new ArrayList<>();

		DesignEntity entity = new DesignEntity();
		//設計書種類ID
		entity.setDesignTypeId(modelList.get(0).getSection());
		//画面ID
		entity.setScreenId(modelList.get(2).getSection());
		//画面名
		entity.setScreenName(modelList.get(2).getScreenItemName());
		//TODO 設計書名
		entity.setDesignName(modelList.get(2).getSection());
		//TODO 状態CD
		entity.setCheckStatus("状態CD");
		//登録日
		entity.setLoginDate(LocalDate.now());
		//登録者
		entity.setLoginBy("登録者");
		//更新日
		entity.setUpdateDate(LocalDate.now());
		//更新者
		entity.setUpdatedBy("更新者");
		//有効フラグ
		entity.setEffectiveFlag("Y");
		entity.setVersionNumber("9876543210");

		entityList.add(entity);
		return entityList;
	}

	//画面項目記述書テーブルエンティティにセットする
	private List<ScreenItemDescriptionEntity> setScreenItemDescriptionEntity(List<ScreenItemDescripitonModel> modelList) {

		List<ScreenItemDescriptionEntity> entityList = new ArrayList<>();
		//設計書種類ID
		String designTypeId = modelList.get(0).getSection();
		//画面ID
		String screenId = modelList.get(2).getSection();

		//TODO "6"
		for(ScreenItemDescripitonModel model : modelList.subList(6, modelList.size())) {

			ScreenItemDescriptionEntity entity = new ScreenItemDescriptionEntity();
			entity.setDesignTypeId(designTypeId);
			entity.setScreenId(screenId);
			entity.setSection(Integer.parseInt(model.getSection()));
			entity.setLevelCd(model.getLevelCd());
			entity.setScreenItemName(model.getScreenItemName());
			entity.setScreenItemPhysicsName(model.getScreenItemPhysicsName());
			entity.setIoCd(model.getIoCd());
			entity.setTypeCd(model.getTabCd());
			entity.setAttributeCd(model.getAttributeCd());
			entity.setTabCd(model.getTabCd());
			entity.setRequired(model.getRequired());
			entity.setRangeWide(model.getRangeWide());
			entity.setRangeSmall(model.getRangeSmall());
			entity.setDigitBranch(model.getDigitBranch());
			entity.setNumberBar(model.getNumberBar());
			entity.setDisplayFormatCd(model.getDisplayFormatCd());
			entity.setControlCondition(model.getControlCondition());
			entity.setDataItem(model.getDataItem());
			entity.setStatusCd("状態CD");//TODO 状態CD
			entity.setProcessingId(model.getProcessingId());
			entity.setLoginDate(LocalDate.now());
			entity.setLoginBy("登録者");
			entity.setUpdateDate(LocalDate.now());
			entity.setUpdatedBy("更新者");
			entity.setEffectiveFlag("Y");
			entity.setVersionNumber("0123456789");

			entityList.add(entity);
		}

		return entityList;
	}
}
